﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SalesModel;

namespace SalesModel
{
    [Serializable]
    public class Sale
    {
        private int id_sale;
        private static double totalAmmount;
        private DateTime regDate;
        private String type;
        private double tax;
        private int regMachine;

        private Cashier cashier;

        static int quantSalesDetails = 0;
        private static List<SalesDetail> detailList = new List<SalesDetail>();


        public int Id_sale
        {
            get { return id_sale; }
            set { id_sale = value; }
        }
        public static List<SalesDetail> DetailList
        {
            get { return Sale.detailList; }
            set { Sale.detailList = value; }
        }
        public static double TotalAmmount
        {
            get { return Sale.totalAmmount; }
            set { Sale.totalAmmount = value; }
        }
        public DateTime RegDate
        {
            get { return regDate; }
            set { regDate = value; }
        }
        public String Type
        {
            get { return type; }
            set { type = value; }
        }
        public double Tax
        {
            get { return tax; }
            set { tax = value; }
        }
        public int RegMachine
        {
            get { return regMachine; }
            set { regMachine = value; }
        }

        public SalesDetail getSalesDetailByProduct(Product prod)
        {
            for (int i = 0; i < detailList.Count; i++)
                if (detailList[i].getProduct().getId_product() == prod.getId_product())
                    return detailList[i];
            return null;
        }

        public Cashier getCashier()
        {
            return cashier;
        }

        public void setCashier(Cashier cashier)
        {
            this.cashier = cashier;
        }

        public void addSaleDetail(Product p, int quant)
        {
            SalesDetail sl = new SalesDetail();
            sl.setIdDetail(++quantSalesDetails);
            sl.setProduct(p);
            sl.setQuantity(quant);
            sl.setSubTotal(p.getBasePrice() * quant);

            detailList.Add(sl);
            totalAmmount += sl.getSubTotal();
        }

        public List<SalesDetail> showSaleDetail()
        {
            return detailList;
            /*
            for(int i=0; i<detailList.size(); i++){
                detailList.get(i).getProduct().getBasePrice();
            }
            */

        }

        public int getId_sale()
        {
            return id_sale;
        }
        public void setId_sale(int id_sale)
        {
            this.id_sale = id_sale;
        }
        public double getTotalAmmount()
        {
            return totalAmmount;
        }
        public void setTotalAmmount(double tA)
        {
            totalAmmount = tA;
        }
        public DateTime getRegDate()
        {
            return regDate;
        }
        public void setRegDate(DateTime regDate)
        {
            this.regDate = regDate;
        }
        public String getType()
        {
            return type;
        }
        public void setType(String type)
        {
            this.type = type;
        }
        public double getTax()
        {
            return tax;
        }
        public void setTax(double tax)
        {
            this.tax = tax;
        }
        public int getRegMachine()
        {
            return regMachine;
        }
        public void setRegMachine(int regMachine)
        {
            this.regMachine = regMachine;
        }
    }
}
